﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using Casanova.Web;
using Domain.DAL;

namespace WebApp.Reports.Bussiness
{
    public class RepairingTicketListBUS
    {
        #region Statis Methods

        public static DataSet GetDataSource(string repairingTicketHistoryIDs)
        {
            DataSet source = new DataSet();
            try
            {
                if (!string.IsNullOrEmpty(repairingTicketHistoryIDs))
                {
                    string ids = InitRepairingTicketHistoryIDs(repairingTicketHistoryIDs);
                    if (!string.IsNullOrEmpty(ids))
                    {
                        RepairingTicketDAO rtDAO = RepairingTicketDAO.GetInstance();
                        if (rtDAO != null)
                        {
                            source = rtDAO.GetForPrintTemplate(ids);
                        }
                    }
                }
            }
            catch (Exception)
            {
                source.Dispose();
                throw;
            }
            return source;
        }

        private static string InitRepairingTicketHistoryIDs(string repairingTicketHistoryIDs)
        {
            string result = string.Empty;

            if (!string.IsNullOrEmpty(repairingTicketHistoryIDs))
            {
                string[] ids = repairingTicketHistoryIDs.Split(new string[] {"@"}, StringSplitOptions.RemoveEmptyEntries);
                if (ids != null && ids.Length > 0)
                {
                    foreach (string id in ids)
                    {
                        result = result + "'" + id + "',";
                    }

                    if (result.Trim().Length > 0)
                    {
                        result = result.Substring(0, result.Length - 1);
                    }
                }
            }
            return result;
        }

        #endregion
    }
}